package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.ArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    //学院列表查询
   @GetMapping
    public Result selectStudent(StudentQueryParam studentQueryParam){
       PageResult<Student> pageResult = studentService.selectStudent(studentQueryParam);
       return Result.success(pageResult);


   }

   //删除学员
    @DeleteMapping("/{ids}")
    public Result deleteStudent(@PathVariable("ids") List<Integer> ids){
       log.info("接收到的参数ids:" + ArrayUtil.toString(ids));
       studentService.deleteStudent(ids);
       return Result.success();
    }

    //添加学员
    @PostMapping
    public Result postStudent(@RequestBody Student student){
       studentService.postStudent(student);
       return Result.success();
    }

    //修改学员信息
    //1. 数据回显.根据id
    @GetMapping("/{id}")
    public Result getStudentById(@PathVariable("id") Integer id){
       Student student = studentService.getStudentById(id);
       return Result.success(student);
    }
    //2.修改信息
    @PutMapping
    public Result putStudent(@RequestBody Student student){
       studentService.putStudent(student);
       return Result.success();
    }


}
